package com.cskaoyan.market.controller.admin;

import com.cskaoyan.market.service.admin.MarketStatService;
import com.cskaoyan.market.util.ResponseUtil;
import com.cskaoyan.market.vo.StatGoodVo;
import com.cskaoyan.market.vo.StatOrderVo;
import com.cskaoyan.market.vo.StatUserVo;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName AdminStatController
 * @Description
 * @Author MZ
 * @Date 2023/5/9 21:05
 */
@RequiresAuthentication
@RestController
@RequestMapping("admin/stat")
public class AdminStatController {
    @Autowired
    private MarketStatService statService;

    @GetMapping("goods")
    public Object goods() {
        Map<String, Object> result = new HashMap<>();
        List<String> columns = new ArrayList<>();
        // "day","orders","products","amount"
        columns.add("day");
        // 订单量 统计每天的id个数
        columns.add("orders");
        // 累加每天的number
        columns.add("products");
        // 订单总额  累加每天的price
        columns.add("amount");

        List<StatGoodVo> rows = statService.statGoods();
        result.put("columns", columns);
        result.put("rows", rows);

        return ResponseUtil.ok(result);
    }

    @GetMapping("order")
    public Object order() {
        Map<String, Object> result = new HashMap<>();
        List<String> columns = new ArrayList<>();
        columns.add("day");
        // 订单量
        columns.add("orders");
        // 下单用户
        columns.add("customers");
        // 订单总额
        columns.add("amount");
        // 客单价
        columns.add("pcr");

        List<StatOrderVo> rows = statService.statOrders();

        result.put("columns", columns);
        result.put("rows", rows);

        return ResponseUtil.ok(result);
    }

    @GetMapping("user")
    public Object user() {
        Map<String, Object> result = new HashMap<>();

        List<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("users");

        List<StatUserVo> rows = statService.statUsers();

        result.put("columns", columns);
        result.put("rows", rows);

        return ResponseUtil.ok(result);
    }
}
